package com.jd.webapp.portal.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.jd.common.convention.TTResult;
import com.jd.common.util.HttpClientUtil;
import com.jd.webapp.portal.pojo.User;

@Service
public class UserServiceImpl implements UserService {
	@Value("${SSO_BASE_URL}")
	public String SSO_BASE_URL;

	@Override
	public User getUserByToken(String token) throws Exception {
		//调用sso系统的服务，根据token取用户信息
		String json = HttpClientUtil.doGet(SSO_BASE_URL + "/user/token/" + token);
		//把json转换成TaotaoREsult
		TTResult result = TTResult.formatToPojo(json, User.class);
		if (result.getStatus() == 200) {
			User user = (User) result.getData();
			return user;
		}else{
			return null;
		}
	}

}
